package com.door.erp.sevice.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.door.erp.dao.PurchaseOrderDao;
import com.door.erp.dao.base.GenericDao;
import com.door.erp.model.PurchaseOrder;
import com.door.erp.sevice.PurchaseOrderService;
import com.door.erp.sevice.base.GenericServiceImpl;

@Service(value="purchaseOrderService")
public class PurchaseOrderServiceImpl extends
		GenericServiceImpl<PurchaseOrder, Long> implements PurchaseOrderService {

	@Resource(name="purchaseOrderDao", type=PurchaseOrderDao.class)
	private PurchaseOrderDao purchaseOrderDao;

	@Override
	public GenericDao<PurchaseOrder, Long> getDao() {
		return this.purchaseOrderDao;
	}

	@Override
	public List<PurchaseOrder> getPurchaseOrdersByTime(String beginTimeStr,
			String endTimeStr) {
		SimpleDateFormat  format = new SimpleDateFormat("yyyy-MM-dd");
		Date beginTime = null;
		Date endTime = null;
		try {
			beginTime = format.parse(beginTimeStr);
			endTime = format.parse(endTimeStr);
			endTime = new Date(endTime.getTime() + 24 * 60 * 60 * 1000);
		} catch (ParseException e1) {
			e1.printStackTrace();
			return null;
		}
		return this.purchaseOrderDao.getPurchaseOrdersByTime(beginTime, endTime);
	}
}
